package com.cn.springcloudvaccine.utils.commen;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {

    /**
     * 时间转换成时间戳
     * @param time
     * @return
     */
    public static long dateToTimestamp(String time){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = simpleDateFormat.parse(time);
            long ts = date.getTime() / 1000;
            return ts;
        } catch (Exception e) {
            return 0;
        }
    }

    /**
     * 时间戳转时间(11位时间戳)
     * @param time
     * @return
     */
    public static String timestampToDate(long time) {
        String dateTime;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        dateTime = simpleDateFormat.format(new Date(time * 1000L));
        return dateTime;
    }

}
